package com.yaoxuguang.concurrence.timer;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

/**
 * @author yaoxuguang
 * @Title: yao-interview
 * @Package com.yaoxuguang.concurrence.timer
 * @Description: 定时器timer的schedule方法
 * @date 2018年12月25日10:42
 */
public class TimerTest1 {
    public static void main(String[] args) {
        try {
            TimerTask task = new TimerTask() {
                @Override
                public void run() {
                    System.out.println("定时运行测试代码...");
                }
            };
            Timer timer = new Timer();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:sss");
            String dateString = "2018-12-25 10:52:00";
            Date date = sdf.parse(dateString);
            timer.schedule(task,date);
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }
}
